# -*- coding: utf-8 -*-
# @Time    : 2017/11/3 11:32
# @Author  : Deyu.Tian
# @Site    :
# @File    : config.py
# @Software: PyCharm Community Edition

from glob import glob
import glob
import os

def list_of_subdirectories(father_dir):
    return glob("{}/*/".format(father_dir))


def list_all_ncs(folder,pattern='*',ext='nc'):
    """
    列出指定目录及其一级子目录下所有指定格式的文件
    :param folder:指定的目录
    :param pattern:文件名，*是通配符
    :param ext:文件后缀名
    :return:所有符合要求文件的list
    """
    folder_dirs = [x[0] for x in os.walk(folder)]
    filenames=[]
    new_filenames=[]
    for folderdir in folder_dirs:
        filenames.extend(sorted(glob.glob(folderdir+'/' + pattern + '.' + ext)))
    for filename in  filenames:
        new_filenames.append(filename.replace('\\','/'))
    return new_filenames

def list_all_txts(folder,pattern='*',ext='txt'):
    """
    列出指定目录及其一级子目录下所有指定格式的文件
    :param folder:指定的目录
    :param pattern:文件名，*是通配符
    :param ext:文件后缀名
    :return:所有符合要求文件的list
    """
    folder_dirs = [x[0] for x in os.walk(folder)]
    filenames=[]
    new_filenames=[]
    for folderdir in folder_dirs:
        filenames.extend(sorted(glob.glob(folderdir+'/' + pattern + '.' + ext)))
    for filename in  filenames:
        new_filenames.append(filename.replace('\\','/'))
    return new_filenames


def list_all_tifs(folder,pattern='*',ext='tif'):
    """
    列出指定目录及其一级子目录下所有指定格式的文件
    :param folder:指定的目录
    :param pattern:文件名，*是通配符
    :param ext:文件后缀名
    :return:所有符合要求文件的list
    """
    folder_dirs = [x[0] for x in os.walk(folder)]
    filenames=[]
    new_filenames=[]
    for folderdir in folder_dirs:
        filenames.extend(sorted(glob.glob(folderdir+'/' + pattern + '.' + ext)))
    for filename in  filenames:
        new_filenames.append(filename.replace('\\','/'))
    return new_filenames
